<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .open{
            display: flex;
            border-bottom: 1px solid ;
            width: 450px;
            padding: 10px;
            justify-content: space-around;
            margin: 0 auto;
        }
        button{
            width: 50px;
            height: 30px;
        }
        input{
            padding-left: 15px;
        }
    </style>
</head>
<body>
    <div class="open">
        <p>华为</p>
        <span>3000￥</span>
        <button class="jian">-</button>
        <input type="text" placeholder="1">
        <button class="jia">+</button>
    </div>
    <div class="open">
        <p>荣耀</p>
        <span>3000￥</span>
        <button class="jian">-</button>
        <input type="text" placeholder="1">
        <button class="jia">+</button>
    </div>
    <div class="open">
        <p>小米</p>
        <span>2000￥</span>
        <button class="jian">-</button>
        <input type="text" placeholder="1">
        <button class="jia">+</button>
    </div>
    <div>价格：<span class="jiage">8000</span></div>
    <div>数量：<span class="shu">3</span></div>
    <script>
        function sum(arr){
           let ge=[3000,3000,2000]
           let shuliang=0
           let zongjia=0
           arr.forEach(function(open,i){
                shuliang+= +open
                zongjia+=open*ge[i]
           })
           return {shuliang:shuliang,zongjia:zongjia}
           console.log(shuliang,zongjia);
        }
        let jian=document.querySelectorAll('.jian')
        let inp=document.querySelectorAll('.open>input')
        let jia=document.querySelectorAll('.jia')
        let jiage=document.querySelector('.jiage')
        let shu=document.querySelector('.shu')
        jian.forEach(function(open,i){
            open.addEventListener('click',function(){
                // console.log(inp[i].placeholder);
                let arr=[]
               inp[i].placeholder--
               if(inp[i].placeholder<=1){
                inp[i].placeholder=1
               }
               inp.forEach(function(open){
                    
                    arr[arr.length]=open.placeholder
               })
               
                let jieguo= sum(arr)
                console.log(jia);
               jiage.innerHTML=jieguo.zongjia
               shu.innerHTML=jieguo.shuliang  

            })
        })
        jia.forEach(function(open,i){
            open.addEventListener('click',function(){
                // console.log(inp[i].placeholder);
                let arr=[]
               inp[i].placeholder++
              
               inp.forEach(function(open){
                    
                    arr[arr.length]=open.placeholder
               })
               
               let jieguo= sum(arr)
                console.log(jia);
               jiage.innerHTML=jieguo.zongjia
               shu.innerHTML=jieguo.shuliang  

            })
        })
        
    </script>
</body>
</html>